unit uMainUtils;

interface

uses gnugettext, Oracle, dialogs, ScktComp, graphics, classes, strutils, sysutils, OracleData, Forms, variants, grids, uupdateapp;

type
  TMainUtils = class(TComponent)
    Constructor Create; virtual;
    procedure TournamentPlayerFromTable(TicketID, TournamentID, DateTimeStr, WinPos: string);
    function GetFieldNameText(OrigFieldNm: string): string;
  end;

var
  OraQueryMainUtils: TOracleQuery;
  OraSessMainUtils: TOracleSession;
  OracleDataSetCashGame: TOracleDataSet;
  OracleDataSetTournament: TOracleDataSet;
  OracleDataTables: TOracleDataSet;
  OracleDataDealers: TOracleDataSet;
  Currency_Symbol: string;
procedure ClearBreakTableData();
procedure SetOracleSession(MainForm: TComponent; OracleSession: TOracleSession; APPUsername, APPPassword: string);
procedure UpdateDataToDB(TableNm, UpdateFields, WhereCond: string);
procedure InsertDataTrack(Operation, TableNm, Query: string);
function InsertDataIntoDB(TableNm, FieldNames, FieldValues: string): string;
procedure GetHallDataSetsData();
procedure DeleteDataFromDB(TableNm, WhereCond: string);
procedure InsertRebuyOrAddon(IsCashGame, IsRebuy, OnTable: Boolean; TicketID, Value, TournamentID: string);
procedure ExtractTranslationFilesFromEXE;
procedure SaveResourceAsFile(const ResName: string; ResType: PChar; const Filename: string);
procedure TableFromTournament(TicketID, TournamentID: string);
procedure ClearStringGrid(Grid: TStringGrid);
function CheckAddonRebuyFinished(IsCashGame: Boolean; DoRebuyId: string; DoAddonId: string): Boolean;

const
  ColorTicketRebuy: TColor = $00558CFF;
  ColorTicketOut: TColor = clGray;
  ColorTicketPaid: TColor = $0080FF80;
  ColorTicketToPay: TColor = $006464FF;
  ColorTournamentRunning: TColor = $007DA5FF;
  ColorTournamentSeating: TColor = $007DA5FF;
  ColorTournamentFinished: TColor = $0080FFFF;
  ColorTournamentAnnounced: TColor = $00B3E0E1;
  ColorTournamentPaused: TColor = $007DA5FF;

implementation

uses uutils;

function CheckAddonRebuyFinished(IsCashGame: Boolean; DoRebuyId: string; DoAddonId: string): Boolean;
begin
  result := false;
  if (DoRebuyId = '') and (DoAddonId = '') then
  begin
    exit;
  end;
  if IsCashGame then
  begin
    OraQueryMainUtils.SQL.Clear;
    OraQueryMainUtils.SQL.Text := ('select id from CASH_GAME_TICKET_REBUYS where accept_datetime is null and id=' + DoRebuyId);
    OraQueryMainUtils.Execute;
    if OraQueryMainUtils.Eof then
    begin
      result := true;
    end;
  end
  else
  begin
    // addon
    if DoAddonId <> '' then
    begin
      OraQueryMainUtils.SQL.Clear;
      OraQueryMainUtils.SQL.Text := ('select id from TICKET_ADDON where value is null and id=' + DoAddonId);
      OraQueryMainUtils.Execute;
      if OraQueryMainUtils.Eof then
      begin
        result := true;
      end;
    end;
    // addon
    if DoRebuyId <> '' then
    begin
      OraQueryMainUtils.SQL.Clear;
      OraQueryMainUtils.SQL.Text := ('select id from TICKET_REBUY where value is null and id=' + DoRebuyId);
      OraQueryMainUtils.Execute;
      if OraQueryMainUtils.Eof then
      begin
        result := true;
      end;
    end;
  end;
end;

procedure InsertRebuyOrAddon(IsCashGame, IsRebuy, OnTable: Boolean; TicketID, Value, TournamentID: string);
var
  SQLvalues: string;
begin
  if IsCashGame then
  begin
    SQLvalues := TicketID + ', ' + 'to_date(''' + GetFormatedStringDateNOW(OraSessMainUtils) + ''', ''dd.mm.yyyy hh24:mi:ss'')' + ', ' + '''' + Value + '''' + ',' + BtoStr(OnTable)
      + ',' + TournamentID;
    InsertDataIntoDB('CASH_GAME_TICKET_REBUYS', 'CASH_GAME_TICKET_ID, DATETIME, VALUE, ON_TABLE, CASH_GAME_ID', SQLvalues);
  end
  else // is tournament
  begin
    if IsRebuy then
    begin
      SQLvalues := TicketID + ', ' + 'to_date(''' + GetFormatedStringDateNOW(OraSessMainUtils) + ''', ''dd.mm.yyyy hh24:mi:ss'')' + ', ' + '''' + Value + '''' + ',' + BtoStr(OnTable)
        + ',' + TournamentID;
      InsertDataIntoDB('TICKET_REBUY', 'TICKET_ID, DATETIME, VALUE, ON_TABLE, TOURNAMENT_ID', SQLvalues);
    end
    else // is addon
    begin
      // check if player already have addon
      OraQueryMainUtils.SQL.Clear;
      OraQueryMainUtils.SQL.Text := ('select id from TICKET_ADDON where ticket_id=' + TicketID);
      OraQueryMainUtils.Execute;
      if not OraQueryMainUtils.Eof then
      begin
        ShowMessage(_('Player already have ADDON!'));
        exit;
      end
      else
      begin
        // --------------
        SQLvalues := TicketID + ', ' + 'to_date(''' + GetFormatedStringDateNOW(OraSessMainUtils) + ''', ''dd.mm.yyyy hh24:mi:ss'')' + ', ' + '''' + Value + '''' + ',' + BtoStr(OnTable)
          + ',' + TournamentID;
        InsertDataIntoDB('TICKET_ADDON', 'TICKET_ID, DATETIME, VALUE, ON_TABLE, TOURNAMENT_ID', SQLvalues);
      end;
    end;
  end;
end;

procedure ClearStringGrid(Grid: TStringGrid);
var
  I: Integer;
  J: Integer;
  AddRow: Integer;
begin
  if Grid.RowCount < 10000 then
  begin
    if Grid.FixedRows > 0 then
      AddRow := 1
    else
      AddRow := 0;
    for I := 0 to Grid.ColCount - 1 do
      for J := Grid.FixedRows + AddRow to Grid.RowCount - 1 do
        Grid.Cells[I, J] := '';
    Grid.RowCount := Grid.FixedRows + AddRow;
  end;
end;

procedure SetOracleSession(MainForm: TComponent; OracleSession: TOracleSession; APPUsername, APPPassword: string);
begin
  OraQueryMainUtils := TOracleQuery.Create(MainForm);
  OraSessMainUtils := TOracleSession.Create(MainForm);
  OraSessMainUtils := OracleSession;
  OraQueryMainUtils.Session := OraSessMainUtils;
  OracleDataSetCashGame := TOracleDataSet.Create(MainForm);
  OracleDataSetTournament := TOracleDataSet.Create(MainForm);
  OracleDataTables := TOracleDataSet.Create(MainForm);
  OracleDataDealers := TOracleDataSet.Create(MainForm);
  CheckForApplicationUpdate(UpperCase(ExtractFileName(Application.ExeName)), APPUsername, APPPassword);
end;

procedure GetHallDataSetsData();
begin
  OracleDataSetCashGame.Session := OraSessMainUtils;
  OracleDataSetCashGame.Close;
  OracleDataSetCashGame.SQL.Clear;
  OracleDataSetCashGame.SQL.Text :=
    'SELECT CG.ID AS CASH_GAME_ID, CGT.PLAYER_ID, CASE WHEN PL.NICKNAME IS NOT NULL THEN PL.NICKNAME ELSE PL.NAME END AS NAME,SEAT_NUM, TABLE_ID, CGT.ID AS TICKET_ID  FROM TABLES TA LEFT JOIN CASH_GAMES CG ON'
    + ' CG.TABLE_ID=TA.ID LEFT JOIN CASH_GAME_TICKETS CGT ON CGT.CASH_GAME_ID =CG.ID LEFT JOIN PLAYERS PL ON PL.ID=CGT.PLAYER_ID' +
    ' WHERE TA.CASH_GAME=1 AND (CGT.OUT_DATETIME IS NULL OR CGT.OUT_DATETIME IS NULL)';
  OracleDataSetCashGame.Open;
  OracleDataSetTournament.Session := OraSessMainUtils;
  OracleDataSetTournament.Close;
  OracleDataSetTournament.SQL.Clear;
  OracleDataSetTournament.SQL.Text := 'SELECT * FROM GET_HALL_TOURNAMENT_DATA';
  OracleDataSetTournament.Open;
  OracleDataTables.Session := OraSessMainUtils;
  OracleDataTables.Close;
  OracleDataTables.SQL.Clear;
  OracleDataTables.SQL.Text := 'SELECT ID, NAME, SEATS, MUST_SET_DEALER, IS_BREAK_TABLE FROM TABLES';
  OracleDataTables.Open;
  OracleDataDealers.Session := OraSessMainUtils;
  OracleDataDealers.Close;
  OracleDataDealers.SQL.Clear;
  OracleDataDealers.SQL.Text := 'SELECT * FROM GET_LOGGED_SUBJECTS';
  OracleDataDealers.Open;
end;

procedure TMainUtils.TournamentPlayerFromTable(TicketID, TournamentID, DateTimeStr, WinPos: string);
var
  PPoints: string;
begin
  // check if some rebuy or addon found, if found cancel from table
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('select id from TICKET_REBUY where ticket_id=' + TicketID + ' and value is null');
  OraQueryMainUtils.Execute;
  if not OraQueryMainUtils.Eof then
  begin
    OraQueryMainUtils.SQL.Clear;
    OraQueryMainUtils.SQL.Text := ('delete from TICKET_REBUY where ticket_id=' + TicketID + ' and value is null');
    OraQueryMainUtils.Execute;
  end;
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('select id from TICKET_ADDON where ticket_id=' + TicketID + ' and value is null');
  OraQueryMainUtils.Execute;
  if not OraQueryMainUtils.Eof then
  begin
    OraQueryMainUtils.SQL.Clear;
    OraQueryMainUtils.SQL.Text := ('delete from TICKET_ADDON where ticket_id=' + TicketID + ' and value is null');
    OraQueryMainUtils.Execute;
  end;
  if DateTimeStr = '' then
  begin
    OraQueryMainUtils.SQL.Clear;
    OraQueryMainUtils.SQL.Text := ('SELECT (TICKET - (SELECT SUM(CASE WHEN OUT_DATETIME<(select sysdate from dual)THEN COUNT(1) ELSE 0 END) AS POSITIONS FROM TICKETS WHERE TOURNAMENT_ID=' +
        TournamentID + ' AND DELETED=0 GROUP BY OUT_DATETIME)) AS POSITION FROM(' + ' SELECT COUNT(PLAYER_ID) AS TICKET  FROM TICKETS TI WHERE TOURNAMENT_ID=' + TournamentID + ' AND DELETED=0)');
    OraQueryMainUtils.Execute;
    WinPos := OraQueryMainUtils.Field(0);
    DateTimeStr := 'to_date(''' + uutils.GetFormatedStringDateNOW(OraSessMainUtils) + ''', ''dd.mm.yyyy hh24:mi:ss'')';
  end;
  UpdateDataToDB('TICKETS', 'WIN_POSITION=' + '''' + WinPos + '''' + ',OUT_DATETIME=' + DateTimeStr, 'ID=' + TicketID);
  TableFromTournament(TicketID, TournamentID);
end;

procedure TableFromTournament(TicketID, TournamentID: string);
begin
  // check if table does not have players
  OraQueryMainUtils.Close;
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('SELECT PLAYING, TABLE_ID FROM GET_PLAYERS_PLAY_TICK_BY_TABLE WHERE TOURNAMENT_ID=' + TournamentID + ' AND TABLE_ID=(SELECT TABLE_ID FROM TICKETS WHERE ID=' +
      TicketID + ')');
  OraQueryMainUtils.Execute;
  if not OraQueryMainUtils.Eof then
  begin
    if OraQueryMainUtils.Field(0) = '0' then
    begin
      DeleteDataFromDB('TOURNAMENT_TABLES', 'TABLE_ID=' + VarToStr(OraQueryMainUtils.Field('TABLE_ID')) + ' AND TOURNAMENT_ID=' + TournamentID);
    end;
  end;
end;

procedure UpdateDataToDB(TableNm, UpdateFields, WhereCond: string);
begin
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('update ' + TableNm + ' set ' + UpdateFields + ' where ' + WhereCond);
  OraQueryMainUtils.Execute;
  OraSessMainUtils.Commit;
  InsertDataTrack(UpdateOperation, TableNm, UpdateFields + ' where ' + WhereCond);
end;

function InsertDataIntoDB(TableNm, FieldNames, FieldValues: string): string;
var
  MaxRowId: extended;
  IsInserted: Boolean;
begin
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('select max(id) from ' + TableNm);
  OraQueryMainUtils.Execute;
  MaxRowId := OraQueryMainUtils.Field(0);
  OraQueryMainUtils.SQL.Clear;
  if TableNm <> 'USER_ACCESS' then
  begin
    InsertDataTrack(InsertOperation, TableNm, FieldNames + ' ' + ReplaceStr(FieldValues, '"', ''));
  end;
  IsInserted := false;
  while not IsInserted do
  begin
    MaxRowId := MaxRowId + 1;
    OraQueryMainUtils.SQL.Text := ('insert into ' + TableNm + ' (ID, ' + FieldNames + ') values (''' + FloatToStr(MaxRowId) + ''', ' + FieldValues + ')');
    OraQueryMainUtils.Execute;
    IsInserted := true;
  end;
  result := FloatToStr(MaxRowId);
  OraSessMainUtils.Commit;
end;

procedure InsertDataTrack(Operation, TableNm, Query: string);
var
  MaxRowId: extended;
  FieldNames, FieldValues: string;
begin
  { Query := ReplaceStr(Query, '''', '');
    OraQueryMainUtils.SQL.Clear;
    OraQueryMainUtils.SQL.Text := ('select max(id) from ' + 'DATA_TRACKING');
    OraQueryMainUtils.Execute;
    MaxRowId := OraQueryMainUtils.Field(0);
    MaxRowId := MaxRowId + 1;
    OraQueryMainUtils.SQL.Clear;
    FieldNames := 'USER_ID, DATETIME, COMPUTER_NAME, OPERATION, DB_TABLE, QUERY';
    FieldValues := '''' + LoggedUserId + '''' + ', ' + 'to_date(''' + GetFormatedStringDateNOW(OraSessMainUtils)
    + ''', ''dd.mm.yyyy hh24:mi:ss'')' + ', ' + '''' + ComputerName + '''' + ', ' + '''' + Operation + '''' + ', ' + '''' + TableNm + '''' + ', ' + '''' + Query + '''';
    OraQueryMainUtils.SQL.Text := ('insert into DATA_TRACKING (ID, ' + FieldNames + ') values (''' + FloatToStr(MaxRowId) + ''', ' + FieldValues + ')');
    OraQueryMainUtils.Execute;
    OraSessMainUtils.Commit; }
end;

procedure ExtractTranslationFilesFromEXE;
var
  HomeDirectory: string;
  Language: string;
begin
  HomeDirectory := ExtractFileDir(Application.ExeName);
  HomeDirectory := HomeDirectory + '\Locale';
  if not DirectoryExists(HomeDirectory) then
    CreateDir(HomeDirectory);
  gnugettext.textdomain('LivePokerManager');
  Language := gnugettext.GetCurrentLanguage;
  if Language <> 'EN' then
  begin
    HomeDirectory := HomeDirectory + '\' + Language;
    if not DirectoryExists(HomeDirectory) then
      CreateDir(HomeDirectory);
    HomeDirectory := HomeDirectory + '\LC_MESSAGES';
    if not DirectoryExists(HomeDirectory) then
      CreateDir(HomeDirectory);
    if DirectoryExists(HomeDirectory) then
    begin
      SaveResourceAsFile(Language + '_TRANSLATION', 'MO', HomeDirectory + '\LivePokerManager.mo');
    end;
  end;
end;

procedure SaveResourceAsFile(const ResName: string; ResType: PChar; const Filename: string);
var
  OldFileSize: int64;
  OldFile: file of Byte;
begin
  try
    with TResourceStream.Create(hInstance, ResName, ResType) do
      try
        if FileExists(Filename) then
        begin
          FileMode := fmOpenRead OR fmShareDenyNone;
          AssignFile(OldFile, Filename);
          Reset(OldFile);
          OldFileSize := FileSize(OldFile);
          CloseFile(OldFile);
        end
        else
          OldFileSize := 0;
        if OldFileSize <> Size then
        begin
          SaveToFile(Filename);
        end;
      finally
        Free;
      end;
  except
    on E: EXception do
    begin

    end;
  end;
end;

procedure ClearBreakTableData();
begin
  // all data clear
  UpdateDataToDB('TABLES', 'MUST_SET_DEALER=NULL, IS_BREAK_TABLE=NULL', '0=0');
  UpdateDataToDB('TICKETS', 'BREAK_TO_SEAT_NUM=NULL, BREAK_TO_TABLE_ID=NULL, IS_DEALER=NULL', '0=0');
end;

constructor TMainUtils.Create;
begin
  gnugettext.TranslateComponent(self);
end;

function TMainUtils.GetFieldNameText(OrigFieldNm: string): string;
var
  FieldName: string;
begin
  if OrigFieldNm = 'REBUY_VALUE' then
    FieldName := _('Rebuy') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'NAME' then
    FieldName := _('Name');
  if OrigFieldNm = 'RAKE_VALUE' then
    FieldName := _('Rake') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'DATETIME' then
    FieldName := _('DateTime');
  if OrigFieldNm = 'SURNAME' then
    FieldName := _('Surname');
  if OrigFieldNm = 'BIRTH_DATE' then
    FieldName := _('Birth Date');
  if OrigFieldNm = 'STREET' then
    FieldName := _('Street');
  if OrigFieldNm = 'CITY' then
    FieldName := _('City');
  if OrigFieldNm = 'COUNTRY' then
    FieldName := _('Country');
  if OrigFieldNm = 'IS_CHIP' then
    FieldName := _('Chip');
  if OrigFieldNm = 'FROM_VALUE' then
    FieldName := _('From value');
  if OrigFieldNm = 'TO_VALUE' then
    FieldName := _('To value');
  if OrigFieldNm = 'VALUE' then
    FieldName := _('Value');
  if OrigFieldNm = 'POINTS' then
    FieldName := _('Points');
  if OrigFieldNm = 'IS_PERCENT' then
    FieldName := _('is percent');
  if OrigFieldNm = 'DISABLED' then
    FieldName := _('Disabled');
  if OrigFieldNm = 'SEATS' then
    FieldName := _('Seats');
  if OrigFieldNm = 'FEE' then
    FieldName := _('Fee');
  if OrigFieldNm = 'RAKE' then
    FieldName := _('Rake');
  if OrigFieldNm = 'SEAT_NUM' then
    FieldName := _('Seat Num');
  if OrigFieldNm = 'TICKET_CODE' then
    FieldName := _('Ticket Code');
  if OrigFieldNm = 'DELETED' then
    FieldName := _('Deleted');
  if OrigFieldNm = 'STATE' then
    FieldName := _('State');
  if OrigFieldNm = 'ADDON' then
    FieldName := _('Addon');
  if OrigFieldNm = 'REBUYS' then
    FieldName := _('Rebuys');
  if OrigFieldNm = 'STACK' then
    FieldName := _('Stack');
  if OrigFieldNm = 'RAKE_ID' then
    FieldName := _('Rake');
  if OrigFieldNm = 'DURATION' then
    FieldName := _('Duration');
  if OrigFieldNm = 'IS_BREAK' then
    FieldName := _('Is Break');
  if OrigFieldNm = 'SEQ_INDEX' then
    FieldName := _('Seq Index');
  if OrigFieldNm = 'EVENT_START' then
    FieldName := _('Event Start');
  if OrigFieldNm = 'EVENT_END' then
    FieldName := _('Event End');
  if OrigFieldNm = 'REBUY_ALLOWED' then
    FieldName := _('Rebuy allowed');
  if OrigFieldNm = 'ADDON_ALLOWED' then
    FieldName := _('Addon allowed');
  if OrigFieldNm = 'MODULE' then
    FieldName := _('Module');
  if OrigFieldNm = 'COMPUTER_NAME' then
    FieldName := _('Computer Name');
  if OrigFieldNm = 'USERNAME' then
    FieldName := _('Username');
  if OrigFieldNm = 'PERCENTAGE' then
    FieldName := _('Percentage');
  if OrigFieldNm = 'FROM_NUM' then
    FieldName := _('From Num');
  if OrigFieldNm = 'TO_NUM' then
    FieldName := _('To Num');
  if OrigFieldNm = 'TOURNAMENTS' then
    FieldName := _('Tournaments');
  if OrigFieldNm = 'USERS' then
    FieldName := _('Users');
  if OrigFieldNm = 'WIN_DISTRIBUTION' then
    FieldName := _('Win Distribution');
  if OrigFieldNm = 'WIN_PERCENTAGE' then
    FieldName := _('Win Percentage');
  if OrigFieldNm = 'WIN_PLAYERS_NUMBER' then
    FieldName := _('Win Player Number');
  if OrigFieldNm = 'PLAYERS' then
    FieldName := _('Players');
  if OrigFieldNm = 'PLAYER_NOTES' then
    FieldName := _('Player Notes');
  if OrigFieldNm = 'TABLES' then
    FieldName := _('Tables');
  if OrigFieldNm = 'TOURNAMENT_ROUNDS' then
    FieldName := _('Tournament Rounds');
  if OrigFieldNm = 'BUYS_COUNT' then
    FieldName := _('Buys Count');
  if OrigFieldNm = 'MONEY_PRIZE' then
    FieldName := _('Money Prize') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'TBLE' then
    FieldName := _('Table');
  if OrigFieldNm = 'SEATS_FREE' then
    FieldName := _('Seats Free');
  if OrigFieldNm = 'NOTE' then
    FieldName := _('Note');
  if OrigFieldNm = 'SUM(FEE)' then
    FieldName := _('SUM(FEE)') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'SUM(RAKE)' then
    FieldName := _('SUM(RAKE)') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'SUM_FEE' then
    FieldName := _('Sum Fee') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'SUM_RAKE' then
    FieldName := _('Sum Rake') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'SUM(BUY_IN)' then
    FieldName := _('SUM(BUY_IN)') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'SUM(WIN_VALUE)' then
    FieldName := _('SUM(WIN_VALUE)') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'TOURNAMENTCOUNT' then
    FieldName := _('Tournament Count');
  if OrigFieldNm = 'WIN_CLASSIFICATION' then
    FieldName := _('Win Classification');
  if OrigFieldNm = 'TOURNAMENT' then
    FieldName := _('Tournament');
  if OrigFieldNm = 'WIN_VALUE' then
    FieldName := _('Win Value') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'COUNT_RE_BUY' then
    FieldName := _('Rebuys');
  if OrigFieldNm = 'ON_DISPLAY' then
    FieldName := _('On Display');
  if OrigFieldNm = 'COUNT_ADDON' then
    FieldName := _('Addons');
  if OrigFieldNm = 'LATE_REGISTRATION_MIN' then
    FieldName := _('Late registration min');
  if OrigFieldNm = 'MAX_DURATION' then
    FieldName := _('Max Duration Hours');
  if OrigFieldNm = 'SMALL_BLIND' then
    FieldName := _('Small Blind');
  if OrigFieldNm = 'BIG_BLIND' then
    FieldName := _('Big Blind');
  if OrigFieldNm = 'RAKE_VALUE' then
    FieldName := _('Rake');
  if OrigFieldNm = 'PLAYER_NAME' then
    FieldName := _('Player Name');
  if OrigFieldNm = 'REBUY_OR_ADDON' then
    FieldName := _('Rebuy or Addon');
  if OrigFieldNm = 'STATUS' then
    FieldName := _('Status');
  if OrigFieldNm = 'TABLE_NAME' then
    FieldName := _('Table Name');
  if OrigFieldNm = 'TABLE_ZONE' then
    FieldName := _('Table Zone');
  if OrigFieldNm = 'DRINK_NAME' then
    FieldName := _('Drink name');
  if OrigFieldNm = 'COMPLETED' then
    FieldName := _('Completed');
  if OrigFieldNm = 'BUY_IN' then
    FieldName := _('Buy-In') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'NICKNAME' then
    FieldName := _('Nickname');
  if OrigFieldNm = 'ANTE' then
    FieldName := _('Ante');
  if OrigFieldNm = 'MIN_IN' then
    FieldName := _('Min In') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'BLINDS' then
    FieldName := _('Blinds');
  if OrigFieldNm = 'PLAYER' then
    FieldName := _('Player');
  if OrigFieldNm = 'BREAK' then
    FieldName := _('Break');
  if OrigFieldNm = 'CASH_GAME' then
    FieldName := _('Cash Game');
  if OrigFieldNm = 'DRINK_TYPE' then
    FieldName := _('Drink Type');
  if OrigFieldNm = 'PRICE' then
    FieldName := _('Price') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'OUT_DATETIME' then
    FieldName := _('Out DateTime');
  if OrigFieldNm = 'CURRENT_ROUND' then
    FieldName := _('Current Round');
  if OrigFieldNm = 'WIN_POSITION' then
    FieldName := _('Win Position');
  if OrigFieldNm = 'DISPLAY_ZONE' then
    FieldName := _('Display Zone');
  if OrigFieldNm = 'CAN_MAIL' then
    FieldName := _('Can mail');
  if OrigFieldNm = 'REBUY_ON_TABLE' then
    FieldName := _('Rebuy on table');
  if OrigFieldNm = 'DENOM_VALUE' then
    FieldName := _('Value');
  if OrigFieldNm = 'DENOM_TYPE' then
    FieldName := _('Type');
  if OrigFieldNm = 'PAY_VALUE' then
    FieldName := _('Pay Value') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'INPUT_VALUE' then
    FieldName := _('Input') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'OUTPUT_VALUE' then
    FieldName := _('Output') + #13#10 + Currency_Symbol;
  if OrigFieldNm = 'WIN' then
    FieldName := _('Win') + #13#10 + Currency_Symbol;
  // -----
  if FieldName = '' then
    FieldName := OrigFieldNm;
  result := FieldName;
end;

procedure DeleteDataFromDB(TableNm, WhereCond: string);
begin
  OraQueryMainUtils.SQL.Clear;
  OraQueryMainUtils.SQL.Text := ('delete from ' + TableNm + ' where ' + WhereCond);
  OraQueryMainUtils.Execute;
  OraSessMainUtils.Commit;
  InsertDataTrack(DeleteOperation, TableNm, ' where ' + WhereCond);
end;

end.
